#include "AboutLayer.h"
#include "AudioManage.h"

static const char* CONST_PNG_ABOUT = "Help/about.png";

AboutLayer::AboutLayer()
{
}

AboutLayer::~AboutLayer()
{
}

bool AboutLayer::init()
{
	if (!Layer::init())
	{
		return false;
	}
	AudioManage::buttonSound();

	LayerColor* layerColor = LayerColor::create(cocos2d::Color4B(225, 225, 225, 100));
	this->addChild(layerColor);

	Size size = Director::getInstance()->getVisibleSize();
	Sprite* aboutMenu = Sprite::create(CONST_PNG_ABOUT);
	aboutMenu->setPosition(Vec2(size.width / 2, size.height * 0.6f));
	aboutMenu->setScale(0.7f);

	this->addChild(aboutMenu);

	auto listener1 = EventListenerTouchOneByOne::create();
	listener1->setSwallowTouches(true);
	listener1->onTouchBegan = CC_CALLBACK_0(AboutLayer::callBack, this);

	_eventDispatcher->addEventListenerWithSceneGraphPriority(listener1, this);
	m_listener = listener1;

	return true;
}

bool AboutLayer::callBack()
{
	AudioManage::button2Sound();
	this->setVisible(false);

	_eventDispatcher->removeEventListener(m_listener);

	return true;
}

void AboutLayer::showLayer()
{
	AudioManage::buttonSound();

	this->setVisible(true);

	auto listener1 = EventListenerTouchOneByOne::create();
	listener1->setSwallowTouches(true);
	listener1->onTouchBegan = CC_CALLBACK_0(AboutLayer::callBack, this);

	_eventDispatcher->addEventListenerWithSceneGraphPriority(listener1, this);
	m_listener = listener1;
}